<?php

	class ShopHelper extends AppHelper {
		var $name = 'Shop';
		var $helpers = array('Html', 'Number');
		
		public function __construct($options = array()) {
			$this->View =& ClassRegistry::getObject('view');
			return parent::__construct($options);
		}
		
		public function siteNav() {
			
		}
	
		function menuTop()
		{
			$output = "<ul class=\"menu\">\n";
			$output.= $this->Html->link(__('Portada', true), array('controller' => 'shops', 'shop' => Configure::read('Shop.slug')));
			$output.= $this->Html->link(__('Contacto', true), array('controller' => 'contact', 'shop' => Configure::read('Shop.slug')));
			$output.= "</ul>\n";
			return $output;
		}
		
		function categories($data, $level = 0) {
			return $this->categoriesList($data, $level);
		}
		
		function categoriesList($data, $level = 0) {
			$tabs = '' . str_repeat($this->tab, $level * 2);
			$li_tabs = $tabs . $this->tab;
			$output = $tabs. '<ul class="categories">'."\n";
			foreach ($data as $key=>$val) {
				$output .= $li_tabs . '<li>' . $this->Html->link($val['Taxonomy']['name'], array('shop' => Configure::read('Shop.slug'), 'controller' => 'products', 'action' => 'collections', $val['Term']['slug']))."\n";
				if (isset($val['children'][0])) {
					$output .= $this->categories($val['children'], $level+1);
					$output .= $li_tabs . '</li>'."\n";
				}
				else {
					$output .= '</li>'."\n";
				}
			}
			$output .= $tabs . '</ul>'."\n";
			return $output;
		}
		
		function productsBoxes($products) {
			$output = '';
			if (!empty($products)) {
				$output = '<div class="products">';
				foreach($products AS $row) {
					$output.= '<div class="product">';
					$output.= '<p class="name">' . $this->Html->link($row['ProductDescription']['name'], array('shop' => Configure::read('Shop.slug'), 'controller' => 'products', 'action' => 'details', 'slug' => $row['ProductDescription']['slug'])) . '</p>';
					$image = empty($row['Product']['preview']) ? false : $this->Html->image($row[0]['preview']);
					$output.= '<p class="preview' . (!$image ? ' preview-empty' : '') . '">' . ($image ? $image : '') . '</p>';
					$output.= '<p class="price">' . $row['Currency']['code'] . $this->Number->format($row['Product']['price'], array('before' => $row['Currency']['symbol_left'], 'after' => $row['Currency']['symbol_right'], 'places' => $row['Currency']['decimal_places'], 'decimals' => $row['Currency']['decimals'], 'thousands' => $row['Currency']['thousands'], 'escape' => false)) . '</p>';
					$output.= '</div>';
				}
				$output.= '</div>';
			}
			return $output;
		}
	}
